package com.lxmes.base.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.lxmes.common.utils.SecurityUtils;
import io.swagger.annotations.*;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.lxmes.common.annotation.Log;
import com.lxmes.common.core.controller.BaseController;
import com.lxmes.common.core.domain.AjaxResult;
import com.lxmes.common.enums.BusinessType;
import com.lxmes.base.domain.JcCusInfo;
import com.lxmes.base.service.IJcCusInfoService;
import com.lxmes.common.utils.poi.ExcelUtil;
import com.lxmes.common.core.page.TableDataInfo;

/**
 * 客户基础信息Controller
 * 
 * @author 张志煜
 * @date 2022-08-27
 */
@Api(tags = "客户列表")
@RestController
@RequestMapping("/base/jcCusInfo")
public class JcCusInfoController extends BaseController
{
    @Autowired
    private IJcCusInfoService jcCusInfoService;

    /**
     * 查询客户基础信息列表
     */
    @PreAuthorize("@ss.hasPermi('base:jcCusInfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(JcCusInfo jcCusInfo)
    {
        startPage();
        jcCusInfo.setDeptId(SecurityUtils.getDeptId());
        List<JcCusInfo> list = jcCusInfoService.selectJcCusInfoList(jcCusInfo);
        return getDataTable(list);
    }


    /**
     * 查询客户信息列表
     */
    @ApiOperation(value="移动客户列表")
    //查询条件
    @ApiImplicitParams({
            @ApiImplicitParam(name = "queryParams", value = "客户名称", paramType="query", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "pageSize", value = "分页大小",  required = true,paramType="query",  dataType = "int", dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "pageNum", value = "当前页数",  required = true,paramType="query",   dataType = "int", dataTypeClass = Integer.class)
    })
    @ApiResponses({@ApiResponse(code=200,message = "0k",response = JcCusInfo.class)})
    @GetMapping("/mobileJcCusInfoList")
    public TableDataInfo mobileJcCusInfoList(JcCusInfo jcCusInfo)
    {
        jcCusInfo.setDeptId(SecurityUtils.getDeptId());
        startPage();
        List<JcCusInfo> list = jcCusInfoService.mobileJcCusInfoList(jcCusInfo);
        return getDataTable(list);
    }




    /**
     * 导出客户基础信息列表
     */
    @PreAuthorize("@ss.hasPermi('base:jcCusInfo:export')")
    @Log(title = "客户基础信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, JcCusInfo jcCusInfo)
    {
        jcCusInfo.setDeptId(SecurityUtils.getDeptId());
        List<JcCusInfo> list = jcCusInfoService.selectJcCusInfoList(jcCusInfo);
        ExcelUtil<JcCusInfo> util = new ExcelUtil<JcCusInfo>(JcCusInfo.class);
        util.exportExcel(response, list, "客户基础信息数据");
    }

    /**
     * 获取客户基础信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('base:jcCusInfo:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(jcCusInfoService.selectJcCusInfoById(id));
    }

    /**
     * 新增客户基础信息
     */
    @PreAuthorize("@ss.hasPermi('base:jcCusInfo:add')")
    @Log(title = "客户基础信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody JcCusInfo jcCusInfo)
    {    jcCusInfo.setDeptId(SecurityUtils.getDeptId());
        return toAjax(jcCusInfoService.insertJcCusInfo(jcCusInfo));
    }

    /**
     * 修改客户基础信息
     */
    @PreAuthorize("@ss.hasPermi('base:jcCusInfo:edit')")
    @Log(title = "客户基础信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody JcCusInfo jcCusInfo)
    {
        return toAjax(jcCusInfoService.updateJcCusInfo(jcCusInfo));
    }

    /**
     * 删除客户基础信息
     */
    @PreAuthorize("@ss.hasPermi('base:jcCusInfo:remove')")
    @Log(title = "客户基础信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(jcCusInfoService.deleteJcCusInfoByIds(ids));
    }
}
